package edu.uta.components;
import edu.uta.ui.R;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
/**
 *  @author fall 2011 team5
 */
//reference https://github.com/galex/android-mapviewballoons/blob/master/

public class BalloonOverlayView extends FrameLayout {

	/**
	 * @uml.property  name="layout"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private LinearLayout layout;
	/**
	 * @uml.property  name="title"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private TextView title;
	
	private TextView titleForecast;
	/**
	 * @uml.property  name="snippet"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private TextView snippet;
	
	private TextView snippetForecast;
	/**
	 * @uml.property  name="aqiImage"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private ImageView aqiImage;
	
	private ImageView aqiImageForecast;

	/**
	 * Create a new BalloonOverlayView.
	 *
	 * @param context - The activity context.
	 * @param balloonBottomOffset - The bottom padding (in pixels) to be applied
	 * when rendering this view.
	 */
	public BalloonOverlayView(Context context, int balloonBottomOffset) {

		super(context);

		setPadding(10, 0, 10, balloonBottomOffset);
		layout = new LinearLayout(context);
		layout.setVisibility(VISIBLE);

		LayoutInflater inflater = (LayoutInflater) context
		.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(R.layout.balloon_overlay, layout);
		title = (TextView) v.findViewById(R.id.balloon_item_title);
		snippet = (TextView) v.findViewById(R.id.balloon_item_snippet);
		aqiImage =(ImageView)v.findViewById(R.id.aqi_img);
		titleForecast =(TextView)v.findViewById(R.id.balloon_item_forecast_title);
		snippetForecast =(TextView)v.findViewById(R.id.balloon_item_forecast_snippet);
		aqiImageForecast =(ImageView)v.findViewById(R.id.aqi_forecast_img);
		

		ImageView close = (ImageView) v.findViewById(R.id.close_img_button);
		//close.setBackgroundColor(Color.rgb(244,238,224));
		close.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				layout.setVisibility(GONE);
			}
		});

		FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
				android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
		params.gravity = Gravity.NO_GRAVITY;

		addView(layout, params);

	}

	/**
	 * Sets the view data from a given overlay item.
	 *
	 * @param item - The overlay item containing the relevant view data
	 * (title and snippet).
	 */
	public void setData(BalloonOverlayItem item) {

		layout.setVisibility(VISIBLE);
		if (item.getTitle() != null) {
			title.setVisibility(VISIBLE);
			title.setText(item.getTitle());
			
			
			//title.setBackgroundColor(Color.rgb(244,238,224));
		} else {
			title.setVisibility(GONE);
		}
		if (item.getSnippet() != null) {
			snippet.setVisibility(VISIBLE);
			snippet.setText(item.getSnippet());
			//snippet.setBackgroundColor(Color.rgb(244,238,224));
			
		} else {
			snippet.setVisibility(GONE);
		}
		
		if (item.getImage() != null) {
			aqiImage.setVisibility(VISIBLE);
			aqiImage.setImageDrawable(item.getImage());
			//snippet.setBackgroundColor(Color.rgb(244,238,224));
			
		} else {
			aqiImage.setVisibility(GONE);
		}
		
		if (item.getForecast()!= null) {
			titleForecast.setVisibility(VISIBLE);
			titleForecast.setText(item.getForecast());
			
			
			//title.setBackgroundColor(Color.rgb(244,238,224));
		} else {
			titleForecast.setVisibility(GONE);
		}
		
		if (item.getForecastdesc()!= null) {
			snippetForecast.setVisibility(VISIBLE);
			snippetForecast.setText(item.getForecastdesc());
			
			
			//title.setBackgroundColor(Color.rgb(244,238,224));
		} else {
			snippetForecast.setVisibility(GONE);
		}
		
		if (item.getImageForecast()!= null) {
			
			
			aqiImageForecast.setVisibility(VISIBLE);
			aqiImageForecast.setImageDrawable(item.getImageForecast());
			//snippet.setBackgroundColor(Color.rgb(244,238,224));
			
		} else {
			
			aqiImageForecast.setVisibility(GONE);
		}

	}

}